package com.tjtt.gwm.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;

import com.tjtt.gwm.bean.TdmEquipmentMain;
import com.tjtt.gwm.dao.EquipmentDao;
import com.tjtt.tdm.base.BaseHibernateDao;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.base.PubMethod;
import com.tjtt.tdm.base.StringUtil;

public class EquipmentDaoImpl extends BaseHibernateDao implements EquipmentDao {

	
	public void deleteData(Object object) {
		this.getHibernateTemplate().delete(object);
	}

	
	public Object getDataById(Class clazz, Long id) {
		return this.getHibernateTemplate().get(clazz, id);
	}

	public PageResult queryDataList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from kl_yiqi t ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select * from from kl_yiqi t ");
		if(null!=filterMap && !filterMap.isEmpty()){
//			if(null!=filterMap.get("EQU_NAME") && !"".equals(filterMap.get("EQU_NAME"))){
//				queryString.append(" and t3.equipment_name like '%"+filterMap.get("EQU_NAME")+"%'");
//				countString.append(" and t3.equipment_name like '%"+filterMap.get("EQU_NAME")+"%'");
//			}
		}
		queryString.append(" order by t.id desc");
		String sidx =(String)filterMap.get("sidx"); 
		String sord =(String)filterMap.get("sord"); 
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}

	
	public void saveObject(Object object) {
		this.getHibernateTemplate().save(object);
	}

	
	public void updateObject(Object object) {
		this.getHibernateTemplate().update(object);
	}
	
	public List queryDataBySql(String sql){
   	 Query query = getSession().createSQLQuery(sql);
  	     List list = query.list();
  	     return list;
   }
	
	public void exeSql(String sql){
		 Query query = getSession().createSQLQuery(sql);
		 query.executeUpdate();
	}


	/*
	 * 备件信息
	 */
	public PageResult queryBeijianList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from tdm_beijian t  left join sys_organization t1 on t1.org_id = t.T_CKMC where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id,t1.org_name as T_CKMC,t.t_bjdm,t.t_bjmc,t.t_ggxh,t.t_pinpai,t.t_sjkc from tdm_beijian" +
				" t left join sys_organization t1 on t1.org_id = t.t_ckmc   where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("sb_id") && !"".equals(filterMap.get("sb_id"))){
				queryString.append(" and t.t_sysb= '"+filterMap.get("sb_id")+"'");
				countString.append(" and t.t_sysb = '"+filterMap.get("sb_id")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	

	/*
	 *备件更换历史记录
	 */
	public PageResult queryBeijianghjlList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from tdm_equipment_main t  left join sys_organization t1 on t1.org_id = t.equipment_org_id where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id,t.equipment_htno,t.equipment_sccj,t.equipment_gys,t.equipment_zbqsrq,t.equipment_zbjsrq from tdm_equipment_main t left join sys_organization t1 on t1.org_id = t.equipment_org_id   where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("org_id") && !"".equals(filterMap.get("org_id"))){
				queryString.append(" and t.equipment_org_id = '"+filterMap.get("equipment_org_id")+"'");
				countString.append(" and t.equipment_org_id = '"+filterMap.get("equipment_org_id")+"'");
			}
			if(null!=filterMap.get("shebeiId") && !"".equals(filterMap.get("shebeiId"))){
				queryString.append(" and (t.id = '"+filterMap.get("shebeiId")+"' or t.parent_id ='"+filterMap.get("shebeiId")+"') ");
				countString.append(" and (t.id = '"+filterMap.get("shebeiId")+"' or t.parent_id ='"+filterMap.get("shebeiId")+"')  ");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	/*
	 * 设备基本信息ok 
	 */
	public PageResult queryEqumentBaseList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from tdm_equipment_main t left join sys_organization t1 on t1.org_id = t.equipment_org_id where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id,t1.org_name as EQUIPMENT_ORG_NAME,t.equipment_name,t.equipment_no,t.equipment_ggxh,t.equipment_dw,t.equipment_cfd,t.equipment_ccbh," +
				"t.equipment_sfwfssb,t.equipment_sfwjlsb,t.equipment_gjyfsb,t.equipment_fzr,t.equipment_lxfs,t.equipment_sb_state," +
				"t.equipment_tzsb,t.equipment_zzsb,t.equipment_jsx,t.equipment_jksb,t.equipment_jgqqsrq,t.equipment_jgqjsrq,t.equipment_gdzcbh,t.equipment_gjrq,t.equipment_yjsynx,t.equipment_yjsysj,t.equipment_sfcnx,t.equipment_txsj,t.equipment_psjlfj " +
				"  from tdm_equipment_main t left join sys_organization t1 on t1.org_id = t.equipment_org_id   where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("org_id") && !"".equals(filterMap.get("org_id"))){
				queryString.append(" and t.equipment_org_id = '"+filterMap.get("equipment_org_id")+"'");
				countString.append(" and t.equipment_org_id = '"+filterMap.get("equipment_org_id")+"'");
			}
			if(null!=filterMap.get("shebeiId") && !"".equals(filterMap.get("shebeiId"))){
				queryString.append(" and (t.id = '"+filterMap.get("shebeiId")+"' or t.parent_id ='"+filterMap.get("shebeiId")+"') ");
				countString.append(" and (t.id = '"+filterMap.get("shebeiId")+"' or t.parent_id ='"+filterMap.get("shebeiId")+"')  ");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	/*
	 * 合同信息 ok
	 */
	public PageResult queryHetongList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from  tdm_hetong t   left join tdm_shengccj t1 on t1.id = t.equipment_sccj " +
				" left join gwm_gongyingshang t2  on t2.id = t.equipment_gys    where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id,t.equ_main_id,t.equipment_htno,t1.T_CHANGJIA,t2.gongyingshangname,to_char(t.equipment_zbqsrq,'yyyy-MM-dd'),to_char(t.equipment_zbjsrq,'yyyy-MM-dd'),t.equipment_sbsx,t.equipment_jkzb " +
				"  from tdm_hetong t   left join tdm_shengccj t1 on t1.id = t.equipment_sccj  left join gwm_gongyingshang t2  on t2.id = t.equipment_gys " +
				"  where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("sb_id") && !"".equals(filterMap.get("sb_id"))){
				queryString.append(" and t.equ_main_id = '"+filterMap.get("sb_id")+"'");
				countString.append(" and t.equ_main_id = '"+filterMap.get("sb_id")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	/*
	 * 设备故障ok  真实数据应该是关联设备故障流程查询
	 */
	public PageResult queryShebeigzList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from tdm_equipment_main t  left join sys_organization t1 on t1.org_id = t.equipment_org_id where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.equipment_sbh,t.equipment_gzsj,t.equipment_gzms,t.equipment_sbgz_remark from tdm_equipment_main t left join sys_organization t1 on t1.org_id = t.equipment_org_id   where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("sb_id") && !"".equals(filterMap.get("sb_id"))){
				queryString.append(" and t.equ_main_id = '"+filterMap.get("sb_id")+"'");
				countString.append(" and t.equ_main_id = '"+filterMap.get("sb_id")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	/*
	 * 设备计量
	 */
	public PageResult queryShebeijlList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_MEASUREMENT_INFO t where  1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id,t.EQU_MAIN_ID, t.EQUIPMENT_CLFW,t.EQUIPMENT_GLLB,t.EQUIPMENT_BQDD,t.EQUIPMENT_JHSJSJ,t.EQUIPMENT_JDZT," +
				" t.EQUIPMENT_JDJZRQ,t.EQUIPMENT_JDJZYXQ,t.EQUIPMENT_QRJG,t.EQUIPMENT_JDDW,t.EQUIPMENT_JLLB," +
				" t.EQUIPMENT_JDLX,t.EQUIPMENT_QRFS,t.EQUIPMENT_SJLX,t.EQUIPMENT_JDCD,t.EQUIPMENT_JDJZ_FILE,t.EQUIPMENT_QRBG" +
				" from TDM_MEASUREMENT_INFO t    where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("sb_id") && !"".equals(filterMap.get("sb_id"))){
				queryString.append(" and t.equ_main_id = '"+filterMap.get("sb_id")+"'");
				countString.append(" and t.equ_main_id = '"+filterMap.get("sb_id")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	

	/*
	 * 设备资料ok
	 */
	public PageResult queryShebeizlList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_EQUIPMENT_INFO t   where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.ID,t.EQU_MAIN_ID,t.EQUIPMENT_SBJJ,t.EQUIPMENT_REMARK from TDM_EQUIPMENT_INFO t  where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("sb_id") && !"".equals(filterMap.get("sb_id"))){
				queryString.append(" and t.equ_main_id = '"+filterMap.get("sb_id")+"'");
				countString.append(" and t.equ_main_id = '"+filterMap.get("sb_id")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	/*
	 * 维护保养ok  目前设备维护保养 未开发 无法关联查到数据
	 */
	public PageResult queryWeihbyList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from GWM_SHEBEIWEIBAO t  where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id ,t.shebeiid from  GWM_SHEBEIWEIBAO t  where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("sb_id") && !"".equals(filterMap.get("sb_id"))){
				queryString.append(" and t.shebeiid = '"+filterMap.get("sb_id")+"'");
				countString.append(" and t.shebeiid = '"+filterMap.get("sb_id")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	public List getGongys() {
		String sql = "select id, GONGYINGSHANGNAME from GWM_GONGYINGSHANG";
		Query query = getSession().createSQLQuery(sql);
		return query.list();
	}


	public List getSccj() {
		String sql = "select id, T_CHANGJIA from TDM_SHENGCCJ";
		Query query = getSession().createSQLQuery(sql);
		return query.list();
	}


	//设备属性
	public PageResult querySbsx(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from TDM_SBSX t where 1 = 1 ");
		StringBuffer queryString = new StringBuffer();	
		queryString.append("select t.id,t.SB_SHUXING  from TDM_SBSX t  where 1 = 1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("sx_id") && !"".equals(filterMap.get("sx_id"))){
				queryString.append(" and t.id= '"+filterMap.get("sx_id")+"'");
				countString.append(" and t.id = '"+filterMap.get("sx_id")+"'");
			}
			if(null!=filterMap.get("shuxing") && !"".equals(filterMap.get("shuxing"))){
				queryString.append(" and t.SB_SHUXING= '"+filterMap.get("shuxing")+"'");
				countString.append(" and t.SB_SHUXING = '"+filterMap.get("shuxing")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	
	/**
	 * 查询设备台账信息
	 */
	public PageResult queryEquipmentTz(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();	
		countString.append("select count(*) from kl_yiqi  t  where 1=1 " );
		queryString.append("select t.id,t.yiqimc,t.guigexh,t.zhizaocs,t.zhizaobh from kl_yiqi  t  where 1=1 ");
		String strnow = PubMethod.GetNowDateString();
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("yiqimc") && !"".equals(filterMap.get("yiqimc"))){
				queryString.append(" and t.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
				countString.append(" and t.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
			}
			if(null!=filterMap.get("guigexh") && !"".equals(filterMap.get("guigexh"))){
				queryString.append(" and t.guigexh like '%"+filterMap.get("guigexh")+"%'");
				countString.append(" and t.guigexh like '%"+filterMap.get("guigexh")+"%'");
			}
			if(null!=filterMap.get("type") && "songjianjl".equals(filterMap.get("type"))){
				queryString.append(" and t.xiacidjrq < '"+strnow+"'");
				countString.append(" and t.xiacidjrq < '"+strnow+"'");
			}
			if(null!=filterMap.get("type") && "songxiujl".equals(filterMap.get("type"))){
				queryString.append(" and t.shiyongzt  in ('维护','试验中')");
				countString.append(" and t.shiyongzt  in ('维护','试验中')");
			}
			if(null!=filterMap.get("type") && "jiehuanjl".equals(filterMap.get("type"))){
				queryString.append(" and t.shiyongzt  in ('维护','试验中')");
				countString.append(" and t.shiyongzt  in ('维护','试验中')");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	/*
	 * 获取合同信息
	 */
	public List getHetong(String equMainId,String htId) {
		String sql = ""; 
		if(null !=equMainId && !"".equals(equMainId) && !"undefined".equals(equMainId)){
			sql = "select id, EQUIPMENT_HTNO from TDM_HETONG where EQU_MAIN_ID ="+equMainId;
		}else{
			sql = "select id, EQUIPMENT_HTNO from TDM_HETONG where id= "+htId;
		}
		Query query = getSession().createSQLQuery(sql);
		return query.list();
	}


	/*
	 *根据组织名称获取组织Id
	 */
	public List queryOrgId(String orgName) {
		String sql = "select t.ORG_ID from SYS_ORGANIZATION t where t.ORG_NAME='"+orgName+"'";
		Query query = getSession().createSQLQuery(sql);
		List list = query.list();
		return list;
	}

	/*
	 * 根据用户名称获取用户Id
	 */
	public List queryUserId(String userName) {
		String sql = "select t.USERID from SYS_USERS t where t.USERNAME='"+userName+"'";
		Query query = getSession().createSQLQuery(sql);
		List list = query.list();
		return list;
	}
	public List queryGongysId(String gongysName) {
		String sql = "select t.ID from GWM_GONGYINGSHANG t where t.GONGYINGSHANGNAME='"+gongysName+"'";
		Query query = getSession().createSQLQuery(sql);
		List list = query.list();
		return list;
	}

	public List querySccjId(String sccjName) {
		String sql = "select t.ID from TDM_SHENGCCJ t where t.T_CHANGJIA='"+sccjName+"'";
		Query query = getSession().createSQLQuery(sql);
		List list = query.list();
		return list;
	}
	/*
	 * 根据设备台账名称获取设备台账对象
	 */
	public TdmEquipmentMain queryEquId(String e_name){
		List StandList = this.getHibernateTemplate().find("from TdmEquipmentMain t where t.id =(select min(id) from t  where t.equipmentName='"+e_name+"') ");
		if(StandList != null && StandList.size()>0){
			return (TdmEquipmentMain) StandList.get(0);
		}
		return null;
	}
	/*
	 * 获取合同
	 */
	public List queryHtNo(String htName){
		String sql = "select t.ID from TDM_HETONG t where t.EQUIPMENT_HTNO='"+htName+"'";
		Query query = getSession().createSQLQuery(sql);
		List list = query.list();
		return list;
	}
	/**
	 * 周期检定计划
	 */
	public PageResult queryZhoujList(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();	
		countString.append("select count(*) from tdm_equipment_main t left join tdm_measurement_info t1 on t.id = t1.equ_main_id  " +
						   "left join sys_organization t2 on t2.org_id = t.equipment_org_id  where 1=1");
		queryString.append("select t.id,t2.org_name as EQUIPMENT_ORG_NAME,t.equipment_no,t.equipment_name,t.equipment_ggxh,t.equipment_ccbh,t1.EQUIPMENT_JDJZCS," +
						   "t1.EQUIPMENT_JDZT,t1.EQUIPMENT_QRJG,t1.EQUIPMENT_JHSJSJ,t1.EQUIPMENT_JDJZYXQ,t1.EQUIPMENT_JDDW,t1.EQUIPMENT_JLLB	" +
						   "from tdm_equipment_main t left join tdm_measurement_info t1 on t.id = t1.equ_main_id  " +
						   "left join sys_organization t2 on t2.org_id = t.equipment_org_id where 1=1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("org_id") && !"".equals(filterMap.get("org_id"))){
				queryString.append(" and t2.org_id = '"+filterMap.get("org_id")+"'");
				countString.append(" and t2.org_id = '"+filterMap.get("org_id")+"'");
			}
			if(null!=filterMap.get("shij1") && !"".equals(filterMap.get("shij1"))){
				queryString.append(" and t1.EQUIPMENT_JHSJSJ >= '"+filterMap.get("shij1")+"'");
				countString.append(" and t1.EQUIPMENT_JHSJSJ >= '"+filterMap.get("shij1")+"'");
			}
			if(null!=filterMap.get("shij2") && !"".equals(filterMap.get("shij2"))){
				queryString.append(" and t1.EQUIPMENT_JHSJSJ <= '"+filterMap.get("shij2")+"'");
				countString.append(" and t1.EQUIPMENT_JHSJSJ <= '"+filterMap.get("shij2")+"'");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	@Override
	public PageResult queryEquipmentList(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();	
		countString.append("select count(*) from KL_YIQI  t where  1=1 ");
		queryString.append("select ID,YIQILX,YIQIMC,GUIGEXH,ZHIZAOCS,ZHIZAOBH,JINGDUDJ,CELIANGFW,GOUMAIRQ,ZHERENR," +
				"SUOSHUBMMC,SHIYONGDW,JIANDINGZQ,XIACIDJRQ,TIXINGTS,DAOQIZT,SHIYONGZT,SHIYONGCS from KL_YIQI t where  1=1  ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("yiqilx") && !"".equals(filterMap.get("yiqilx"))){
				queryString.append(" and t.yiqilx like '%"+filterMap.get("yiqilx")+"%'");
				countString.append(" and t.yiqilx like '%"+filterMap.get("yiqilx")+"%'");
			}
			if(null!=filterMap.get("yiqimc") && !"".equals(filterMap.get("yiqimc"))){
				queryString.append(" and t.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
				countString.append(" and t.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
			}
			if(null!=filterMap.get("guigexh") && !"".equals(filterMap.get("guigexh"))){
				queryString.append(" and t.guigexh like '%"+filterMap.get("guigexh")+"%'");
				countString.append(" and t.guigexh like '%"+filterMap.get("guigexh")+"%'");
			}
			if(null!=filterMap.get("zhizaocs") && !"".equals(filterMap.get("zhizaocs"))){
				queryString.append(" and t.zhizaocs like '%"+filterMap.get("zhizaocs")+"%'");
				countString.append(" and t.zhizaocs like '%"+filterMap.get("zhizaocs")+"%'");
			}
			if(null!=filterMap.get("zhizaobh") && !"".equals(filterMap.get("zhizaobh"))){
				queryString.append(" and t.zhizaobh like '%"+filterMap.get("zhizaobh")+"%'");
				countString.append(" and t.zhizaobh like '%"+filterMap.get("zhizaobh")+"%'");
			}
			if(null!=filterMap.get("fuzher") && !"".equals(filterMap.get("fuzher"))){
				queryString.append(" and t.fuzher like '%"+filterMap.get("fuzher")+"%'");
				countString.append(" and t.fuzher like '%"+filterMap.get("fuzher")+"%'");
			}
			if(null!=filterMap.get("org_id") && !"".equals(filterMap.get("org_id"))){
				if (!filterMap.get("org_id").equals("1")){
					queryString.append(" and t.SUOSHUBMID = '"+filterMap.get("org_id")+"'");
					countString.append(" and t.SUOSHUBMID = '"+filterMap.get("org_id")+"'");
				}
			}
			if(null!=filterMap.get("type") && "guoqi".equals(filterMap.get("type"))){
				String strDate = PubMethod.GetNowDateString();
				queryString.append(" and t.xiacidjrq < '"+strDate+"' ");
				countString.append(" and t.xiacidjrq < '"+strDate+"' ");
			}
		}
		queryString.append(" order by t.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	/*
	 * 仪器送检记录
	 * wxj
	 */
	public PageResult queryYiqisjjl(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();	
		countString.append("select count(*) from KL_YIQISJJL t1 left join KL_YIQI t2 on t1.yiqiid=t2.id  where 1=1 ");
		queryString.append("select t1.id,t2.yiqimc,t2.guigexh,t2.zhizaocs,t2.zhizaobh,t1.songjianrq," +
				"t1.songjianr,t1.quhuirq,t1.quhuir,t2.xiacidjrq,t1.state from KL_YIQISJJL t1 left join KL_YIQI t2 on t1.yiqiid=t2.id where 1=1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("yiqilx") && !"".equals(filterMap.get("yiqilx"))){
				queryString.append(" and t2.yiqilx like '%"+filterMap.get("yiqilx")+"%'");
				countString.append(" and t2.yiqilx like '%"+filterMap.get("yiqilx")+"%'");
			}
			if(null!=filterMap.get("yiqimc") && !"".equals(filterMap.get("yiqimc"))){
				queryString.append(" and t2.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
				countString.append(" and t2.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
			}
			if(null!=filterMap.get("guigexh") && !"".equals(filterMap.get("guigexh"))){
				queryString.append(" and t2.guigexh like '%"+filterMap.get("guigexh")+"%'");
				countString.append(" and t2.guigexh like '%"+filterMap.get("guigexh")+"%'");
			}
			if(null!=filterMap.get("state") && !"".equals(filterMap.get("state"))){
				queryString.append(" and t1.state = '"+filterMap.get("state")+"'");
				countString.append(" and t1.state = '"+filterMap.get("state")+"'");
			}
		}
		queryString.append(" order by t1.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}


	@Override
	public PageResult queryYiqisxjl(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();	
		countString.append("select count(*) from KL_YIQISXJL t1 left join KL_YIQI t2 on t1.yiqiid=t2.id  where 1=1 ");
		queryString.append("select t1.id,t2.yiqimc,t2.guigexh,t2.zhizaocs,t2.zhizaobh,t1.songxiurq," +
				"t1.songxiur,t1.quhuirq,t1.quhuir,t1.weixiujg,t1.state from KL_YIQISXJL t1 left join KL_YIQI t2 on t1.yiqiid=t2.id where 1=1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("yiqilx") && !"".equals(filterMap.get("yiqilx"))){
				queryString.append(" and t2.yiqilx like '%"+filterMap.get("yiqilx")+"%'");
				countString.append(" and t2.yiqilx like '%"+filterMap.get("yiqilx")+"%'");
			}
			if(null!=filterMap.get("yiqimc") && !"".equals(filterMap.get("yiqimc"))){
				queryString.append(" and t2.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
				countString.append(" and t2.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
			}
			if(null!=filterMap.get("guigexh") && !"".equals(filterMap.get("guigexh"))){
				queryString.append(" and t2.guigexh like '%"+filterMap.get("guigexh")+"%'");
				countString.append(" and t2.guigexh like '%"+filterMap.get("guigexh")+"%'");
			}
			if(null!=filterMap.get("state") && !"".equals(filterMap.get("state"))){
				queryString.append(" and t1.state = '"+filterMap.get("state")+"'");
				countString.append(" and t1.state = '"+filterMap.get("state")+"'");
			}
		}
		queryString.append(" order by t1.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	
	@Override
	public PageResult queryYiqijhjl(Map filterMap) {
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();	
		countString.append("select count(*) from KL_YIQIJHJL t1 left join KL_YIQI t2 on t1.yiqiid=t2.id  where 1=1 ");
		queryString.append("select t1.id,t2.yiqimc,t2.guigexh,t2.zhizaocs,t2.zhizaobh,t1.peitaofj," +
				"t1.jieyongdw,t1.jieyongr,t1.jieyongrdh,t1.jiechurq,t1.yongtu,t1.shiyongdd,t1.jiechujbr" +
				",t1.guihuanrq,t1.guihuanr,t1.guihuanjbr,t1.state from KL_YIQIJHJL t1 left join KL_YIQI t2 on t1.yiqiid=t2.id where 1=1 ");
		if(null!=filterMap && !filterMap.isEmpty()){
			if(null!=filterMap.get("yiqilx") && !"".equals(filterMap.get("yiqilx"))){
				queryString.append(" and t2.yiqilx like '%"+filterMap.get("yiqilx")+"%'");
				countString.append(" and t2.yiqilx like '%"+filterMap.get("yiqilx")+"%'");
			}
			if(null!=filterMap.get("yiqimc") && !"".equals(filterMap.get("yiqimc"))){
				queryString.append(" and t2.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
				countString.append(" and t2.yiqimc like '%"+filterMap.get("yiqimc")+"%'");
			}
			if(null!=filterMap.get("guigexh") && !"".equals(filterMap.get("guigexh"))){
				queryString.append(" and t2.guigexh like '%"+filterMap.get("guigexh")+"%'");
				countString.append(" and t2.guigexh like '%"+filterMap.get("guigexh")+"%'");
			}
			if(null!=filterMap.get("state") && !"".equals(filterMap.get("state"))){
				queryString.append(" and t1.state = '"+filterMap.get("state")+"'");
				countString.append(" and t1.state = '"+filterMap.get("state")+"'");
			}
		}
		queryString.append(" order by t1.id desc");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
}
